home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 090 / pctj8411.arc / ALIGN.C next >
Text File  |  1986-09-14  |  896b  |  24 lines

  1. /* align.c - align a buffer so that it does not cross */
  2. /* a 64K physical address boundary */
  3. /* We give it the address of a buffer area */
  4. /* It returns a starting address such that the following (size) bytes */
  5. /* do not cross a 64K byte address boundary. */
  6. #include "stdio.h"
  7.  
  8. unsigned get_ds() ;
  9.  
  10. char *align(area,size)        /* align buffer address */
  11.  char *area ;            /* start of buffer area */
  12.  int size ;            /* size required for buffer */
  13.  {                /* returns an aligned address */
  14.     long begin ;        /* flat address for area */
  15.     unsigned room ;        /* number of bytes to boundary */
  16.  
  17.                 /* build flat address */
  18.     begin = ((long) get_ds() ) * 16L + (long) area ;
  19.     room = 0x10000 - (begin & 0xffff) ; /* get distance to boundary */
  20.     if( room >= size )
  21.          return( area ) ;
  22.     else return( area + room ) ;
  23.  }
  24.